package org.common.dispatcher;

import java.lang.reflect.Method;

/**
 * 协议处理方法
 */
public class ProtoWorker {
    // 协议id
    private final int cmdId;
    // 协议处理类的对象
    private final Object handler;
    // 协议处理的方法
    private final Method method;
    // protobuf解析方法
    private final Method protobufDecode;


    public ProtoWorker(int cmdId, Object handler, Method method) throws NoSuchMethodException {
        this.cmdId = cmdId;
        this.handler = handler;
        this.method = method;
        Class<?> parameterType = method.getParameterTypes()[1];
        this.protobufDecode = parameterType.getMethod("parseFrom", byte[].class);
    }

    public int getCmdId() {
        return cmdId;
    }

    public Object getHandler() {
        return handler;
    }

    public Method getMethod() {
        return method;
    }

    public Method getProtobufDecode() {
        return protobufDecode;
    }
}
